<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\common\model;


/**
 * Game模型
 */
class GamesLog extends ModelBase
{

    protected $insert = ['create_time','order_no'];



    /**
     * 流水号自动完成
     */
    public function setOrderNoAttr($value)
    {

        return 'GM'.date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8).rand(1000,9999);
    }
    /**
     * 时间自动完成
     */
    public function setCreateTimeAttr()
    {

        return TIME_NOW;
    }
    //关联赌王表
    public function king(){
        return $this->belongsTo('GamblerKing','king_id','id');
    }

    //关联赌王表
    public function user(){
        return $this->belongsTo('Member','user_id','id');
    }
    //关联下注表
    public function bets(){
        return $this->belongsTo('BetsLog','order_no','trade_no');
    }

    /**
     * 时间自动完成
     */
    public function getCreateTimeAttr($value)
    {

        return date('Y-m-d H:i:s',$value);
    }

    /**
     * 获取状态信息
     */
    public function getStateTextAttr(){
        $arr=['','成功', '进行中' ,'等待开奖' ,'已开奖', '审核中', '失败'];
        return lang($arr[$this->state]);
    }
    /**
     * 获取状态信息
     */
    public function getTypeTextAttr(){
        $arr=['','转出', '转入' ,'' ,'下注', '审核中', '失败'];
        return lang($arr[$this->data['type']]);
    }

}
